#include "RingQueue.hpp"
#include<unistd.h>


void* Product(void* args)
{
    RingQueue<int>* ring=static_cast<RingQueue<int>*>(args);
    while(1)
    {
        
        sleep(2);
        std::cout<<"生产了一个项目"<<std::endl;
        ring->EQueue(1);
    }
    
}


void* Consume(void* args)
{
    RingQueue<int>* ring=static_cast<RingQueue<int>*>(args);
    while(1)
    {
        std::cout<<"消费者消费一个数据"<<std::endl;
        ring->Pop();
    }

}




int main()
{
    RingQueue<int> *ring = new RingQueue<int>();
    pthread_t a[2], p[3];
    pthread_create(&a[0], nullptr, Product, (void *)ring);
    pthread_create(&a[1], nullptr, Product, (void *)ring);
    pthread_create(&p[0], nullptr, Consume, (void *)ring);
    pthread_create(&p[1], nullptr, Consume, (void *)ring);
    pthread_create(&p[2], nullptr, Consume, (void *)ring);



    pthread_join(a[0],nullptr);
    pthread_join(a[1],nullptr);
    pthread_join(p[0],nullptr);
    pthread_join(p[1],nullptr);
    pthread_join(p[2],nullptr);

    return 0;
}